package cn.bytecollege.controller;

import cn.bytecollege.constant.Resource;
import cn.bytecollege.entity.Page;
import cn.bytecollege.entity.UserManage;
import cn.bytecollege.service.OrderService;

import javax.servlet.*;
import javax.servlet.http.*;
import javax.servlet.annotation.*;
import java.io.IOException;

@WebServlet(name = "OrderFindController", value = "/orderFind")
public class OrderFindController extends HttpServlet {
    OrderService orderService=null;
    public OrderFindController(){
        orderService=new OrderService();
    }
    @Override
    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        doPost(request,response);
    }

    @Override
    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        String username=request.getParameter("username");
        String index = request.getParameter("index");
        String size = request.getParameter("size");
        int pageIndex = (index == null) ? 1 : Integer.valueOf(index);
        int pageSize = (size == null) ? 5 : Integer.valueOf(size);
        Page<UserManage> page=orderService.findListByName(pageIndex,pageSize,username);
        if(username==null){
            return;
        }
        request.setAttribute("page",page);
        request.getRequestDispatcher(Resource.PAGE_LOCATION+"/orderList.jsp").forward(request,response);
    }
}
